<template>
	<view class="shopMember">
		<headerVue ref="header" :query="shop_info" @toggle="toggle" @changeIndex="changeHeaderIndex"
			@dateConfirm="dateConfirm"></headerVue>
		<scroll-view scroll-y="true" class="scroll-Y" @scrolltolower="scrolltolower">
			<view class="comlumn_box" v-if="list.length">
				<view v-for="(item,index) in list" :key="index" class="Item">
					<view class="img">
						<image :src="item.avatar" mode="" class="avater"  @click.stop="$PREVIEW_IMAGE(item.avatar)"></image>
						<image
							:src="!item.gender ?$IMG_URL('/static/mannager/girl.png'):$IMG_URL('/static/mannager/boy.png')"
							mode="" class="sex"></image>
					</view>
					<view class="right">
						<view class="title">
							{{item.nickname}}
						</view>
						<view class="bottom">
							<view class="size1">
								{{item.time_str}}
							</view>
						</view>
					</view>
<!-- 					<u-icon name="arrow-right" color="#999999" size="14"></u-icon> -->
				</view>
				<u-loadmore :status="status" />
			</view>
			<empty v-else :content="!activeIndex?'会员':activeIndex == 1?'进行中课程会员':'无课程会员'"></empty>
		</scroll-view>
		<FieldPopupVue :popupShow="popupShow" :FieldList="Field" @sure="sure" @changeActiveIndex="changeActiveIndex"
			:activeIndex="FieldIndex"></FieldPopupVue>
	</view>
</template>

<script>
	import FieldPopupVue from '../../pages/user/components/Field-popup.vue'
	import headerVue from './components/header.vue'
	import {
		storecrossMain,
		atShop,
	} from '@/api/manager.js'
	import empty from './components/empty.vue'
	export default {
		components: {
			FieldPopupVue,
			empty,
			headerVue
		},
		data() {
			return {
				// 切换门店
				popupShow: false,
				Field: [],
				FieldIndex: -1,
				shop_info: {},
				activeIndex: 0,
				query: {
					shop_id: '',
					date: '',
					form: 'day',
					page: 1
				},
				list: [],
				status: 'loadmore', //当前状态
			}
		},
		onLoad() {
			this.getatShop()
		},
		methods: {
			scrolltolower(){
				this.query.page++
				this.getStorecrossMain()
			},
			getStorecrossMain() {
				storecrossMain(this.query).then(({
					data: res
				}) => {
					if (res.code == 1) {
						const list = []
						this.status = 'loading'
						if (this.query.page > res.data.all_page) {
							console.log('nomore');
							this.status = 'nomore'
							return false
						} else {
							console.log('more');
							this.status = 'more'
							this.list = this.list.concat(res.data.list)
						}

						console.log('list', this.list);
					}
				})
			},
			changeHeaderIndex(e) {
				this.query.form = e == 0 ? 'day' : e == 1 ? 'month' : 'year'
				this.query.date = this.$refs.header.day
				this.list = []
				this.query.page = 1
				this.getStorecrossMain()
			},
			dateConfirm(e, data) {
				console.log('e321', data);
				this.query.date = data
				this.list = []
				this.query.page = 1
				this.getStorecrossMain()
			},
			toggle() {
				console.log(11);
				this.popupShow = true
			},
			changeIndex(index) {
				this.activeIndex = index
			},
			getatShop(e) {
				atShop(e).then(({
					data: res
				}) => {
					console.log('res', res);
					if (res.code == 1) {
						this.shop_info = res.data
						this.query.shop_id = res.data.shop_id
						this.list = []
						this.query.page = 1
						this.getStorecrossMain()
					}
				})
			},
			changeActiveIndex(item, index) {
				this.FieldIndex = index
				this.getatShop({
					shop_id: item.shop_id
				})
			},
			sure() {
				this.popupShow = false
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #e9e9e9;
	}

	.shopMember {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.scroll-Y {
		width: 100%;
		height: 80vh;

		.comlumn_box {
			display: flex;
			flex-direction: column;
			align-items: center;
			padding-top: 24rpx;

			.Item {
				width: 702rpx;
				height: 128rpx;
				background: #ffffff;
				border-radius: 16rpx;
				padding: 0 24rpx;
				display: flex;
				flex-direction: row;
				align-items: center;
				margin-bottom: 20rpx;

				.img {
					width: 80rpx;
					height: 80rpx;
					background: #f6f6f6;
					border-radius: 50%;
					position: relative;
					margin-right: 20rpx;

					.avater {
						width: 100%;
						height: 100%;
						border-radius: 50%;
					}

					.sex {
						position: absolute;
						right: 0;
						bottom: 0;
						width: 26rpx;
						height: 26rpx;
					}
				}
			}

			.right {
				display: flex;
				flex-direction: column;
				flex: 1;

				.title {
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC-Bold;
					font-weight: 700;
					text-align: left;
					color: #333333;
					margin-bottom: 2rpx;
				}

				.bottom {
					.size1 {
						font-size: 24rpx;
						font-family: PingFang SC, PingFang SC-Regular;
						font-weight: 400;
						text-align: left;
						color: #000000;
					}

					.size2 {
						font-size: 24rpx;
						font-family: PingFang SC, PingFang SC-Regular;
						font-weight: 400;
						text-align: left;
						color: #b6b6b6;
					}
				}
			}
		}
	}
</style>